<template>
<div>
    <el-table
    :data="tableData"
    style="width: 100%"
    max-height="800">
    <el-table-column
      fixed
      prop="id"
      label="物流id"
      width="400">
    </el-table-column>
    <el-table-column
      prop="handler"
      label="经手人"
      width="400">
    </el-table-column>
    <el-table-column
      prop="reciver"
      label="收货人"
      width="400">
    </el-table-column>
    <el-table-column
      fixed="right"
      label="操作"
      width="220">
      <template slot-scope="scope">
        <el-button
          @click.native.prevent="deleteRow(scope.$index, scope.row)"
          type="text"
          size="small">
          移除
        </el-button>
      </template>
    </el-table-column>
  </el-table>
    <el-pagination
      background
      current-page
      page-size=10
      prev-page="上一页"
      next-page="下一页"
      @current-change="currentPage"
      layout="prev, pager, next , jumper, total"
      :total="total">
    </el-pagination>
</div>
</template>

<script>
import { listTransporttrans,listTransportrecie,listTransportsend,delTrans
          ,getTranslist } from '@/api'
  export default {
    methods: {
      currentPage(page) {
        let _this = this
        if(this.id == 1){
            listTransportsend(page).then((response) => {
                if(response.data.total == 0){
                    _this.$message('无记录');
                }else{
                    _this.total = response.data.total
                    _this.tableData = response.data.list
                    _this.$notify({
                      title: '数据挖掘成功',
                      message: '发货中列表',
                      type: 'success'
                    });
                }
            })
        }
        if(this.id == 2){
            listTransporttrans(page).then((response) => {
                if(response.data.total == 0){
                    _this.$message('无记录');
                }else{
                    _this.total = response.data.total
                    _this.tableData = response.data.list
                    _this.$notify({
                      title: '数据挖掘成功',
                      message: '送货中列表',
                      type: 'success'
                    });
                }
            })
        }
        if(this.id == 3){
            listTransportrecie(page).then((response) => {
                if(response.data.total == 0){
                    _this.$message('无记录');
                }else{
                    _this.total = response.data.total
                    _this.tableData = response.data.list
                    _this.$notify({
                      title: '数据挖掘成功',
                      message: '已签收列表',
                      type: 'success'
                    });
                }
            })
        }
      },
      deleteRow(index, rows) {
        let _this = this
        delTrans(rows.id).then((response) => {
          if(response){
               _this.$alert("删除成功",'删除记录',{
                    confirmButtonText: '确定',
                    callback: action => {
                        location.reload()
              }
          })
        }})
      }
    },
    data() {
      return {
        id:0,
        total:1,
        tableData: []
      }
    },
    created(){
        let id = this.$route.query.id
        this.id = id
        let _this = this
        if(id == 1){
            listTransportsend(1).then((response) => {
                if(response.data.total == 0){
                    _this.$message('无记录');
                }else{
                    _this.total = response.data.total
                    _this.tableData = response.data.list
                    _this.$notify({
                      title: '数据挖掘成功',
                      message: '发货中列表',
                      type: 'success'
                    });
                }
            })
            return
          }
        if(id == 2){
            listTransporttrans(1).then((response) => {
                if(response.data.total == 0){
                    _this.$message('无记录');
                }else{
                    _this.total = response.data.total
                    _this.tableData = response.data.list
                    _this.$notify({
                      title: '数据挖掘成功',
                      message: '送货中列表',
                      type: 'success'
                    });
                }
            })
            return
          }
        if(id == 3){
            listTransportrecie(1).then((response) => {
                if(response.data.total == 0){
                    _this.$message('无记录');
                }else{
                    _this.total = response.data.total
                    _this.tableData = response.data.list
                    _this.$notify({
                      title: '数据挖掘成功',
                      message: '已签收列表',
                      type: 'success'
                    });
                }
            })
            return
          }
        getTranslist().then((response) => {
          if(response){
            _this.tableData = response.data
            _this.$notify({
              title: '数据挖掘成功',
              type: 'success'
            });
          }else{
            _this.$notify({
              title: '数据挖掘失败',
              type: 'warning'
            });
          }
        })
    }
  }
</script>